package com.neuedu.his.service;

import com.neuedu.his.dao.CheckItemDao;
import com.neuedu.his.entity.CheckItem;
import com.neuedu.his.framework.BaseService;
import com.neuedu.his.framework.PageInfo;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * 项目：      his
 * 类名:       CheckItemService
 * 创建时间：  2020/12/23  8:52
 * 描述 :     用户测试类
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
public class CheckItemService implements BaseService<CheckItem> {
    private CheckItemDao checkItemDao = new CheckItemDao();

    @Override
    public List<CheckItem> queryList(HttpServletRequest request) {
        String sql = " select * from check_item where active = 1";
        return checkItemDao.selectList(sql);
    }


    /**
     * 分页查询
     * @param request
     * @return
     * @throws UnsupportedEncodingException
     */
    @Override
    public PageInfo queryListByPage(HttpServletRequest request) throws UnsupportedEncodingException {
        PageInfo pageInfo = getPageInfo(request);

        String name = request.getParameter("name");


        if(name == null ){
            name = "";
        }
        name = "%"+name.trim()+"%";

        String sql = " select * from check_item  where active = 1 and name like ?   limit ?  , ?  ";

        int start = (pageInfo.getPageNo()-1) * pageInfo.getPageSize() ;
        List<CheckItem> list =  checkItemDao.selectList(sql,name, start,pageInfo.getPageSize());

        String sql2 = "  select count(1) from check_item    where active = 1 and name like ?   ";
        long count =  checkItemDao.selectCount(sql2,name);

        pageInfo.setList(list);
        pageInfo.setTotalCount((int) count);

        return pageInfo;
    }

    @Override
    public CheckItem queryById(Integer id) {
        return checkItemDao.selectById(id);
    }

    @Override
    public boolean edit(CheckItem user) {
        return false;
    }


    /**
     * 逻辑删除，没有真正删除数据
     * @param id
     * @return
     */
    @Override
    public boolean deleteById(Integer id) {

        return  checkItemDao.deleteById(id);
    }

    @Override
    public boolean save(CheckItem user) {
        return checkItemDao.insert(user);
    }

    @Override
    public boolean batchdel(String[] ids) throws Exception {
        return false;
    }

    public boolean update(CheckItem user) {
        return checkItemDao.update(user);
    }


}
